var StudentImport = function () {

	var head=`<form action="#" class="form-horizontal">
	<div class="control-group">
	<div class="controls" style="margin-left:30px;margin-top:15px;">
		<div class="row-fluid">`;
		
	var notSignBody=`<div class="span4" style="margin-left:0px;">
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="1" checked disabled="disabled"></span></div>学员姓名
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="2" checked disabled="disabled"></span></div>学员昵称
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="3" checked disabled="disabled"></span></div>家长姓名
				</label>
			</div>
			
			<div class="span4">
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="4" checked disabled="disabled"></span></div>家长关系
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="5" checked disabled="disabled"></span></div>手机号码
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="6"></span></div> 学员生日
				</label>
			</div>
			
			<div class="span4">
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="7"></span></div>学员性别
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="8"></span></div>地址
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="9"></span></div>QQ
				</label>
			</div>
			
			<div class="span4" style="margin-left:0px;">
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="10"></span></div>Email
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="11"></span></div>备用号码
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="12"></span></div>固定电话
				</label>
			</div>
			<div class="span4" >
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="13"></span></div>录入日期
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="14"></span></div>市场人员
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="15"></span></div>顾问
				</label>
			</div>
			<div class="span4">
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="16"></span></div>学员状态
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value=""></span></div>分娩方式
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="17"></span></div>学员来源
				</label>
			</div>
			<div class="span4" style="margin-left:0px;">
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="18"></span></div>首次接触
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="19"></span></div>当前班级
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="20"></span></div>意向课程
				</label>
			</div>
			<div class="span4">
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="21"></span></div>意向时间
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="22"></span></div>重要程度
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="23"></span></div>地区（一级）
				</label>
			</div>
			<div class="span4">
			<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="26"></span></div>组别
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="25"></span></div>基本情况
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="24"></span></div>地区（二级）
				</label>
				
			</div>
			<div class="span4" style="margin-left:0px;">
			<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="30"></span></div>接待人
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="27"></span></div>目前积分
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="28"></span></div>推广日期
				</label>
				<label class="checkbox line">
				<div class="checker"><span class="checked"><input type="checkbox" value="29"></span></div>到访后跟进方式
				</label>
			</div>`;
			
var foot=`</div></div></div></form>`;

var signBody=`
<div class="span4">
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>合同编号
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>业绩所属人
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>合同套餐
	</label>
</div>
<div class="span4">
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>合同金额
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>合同课时
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>合同赠送课时
	</label>
</div>
<div class="span4" style="margin-left:0px;">
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>签约日期
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>起始日期
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>到期日期
	</label>
</div>
<div class="span4">
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>会员卡号
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value="" checked disabled="disabled"></span></div>剩余课时
	</label>
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value=""></span></div>课时类型
	</label>
</div>
<div class="span4">
	<label class="checkbox line">
	<div class="checker"><span class="checked"><input type="checkbox" value=""></span></div>合同备注
	</label>
</div>
`;
    // 未签约模版
    var handleNotSignTemplate = function () {        
    	$("#btn_not_sign").click(function(e){
    		e.preventDefault();
    		
    		layer.open({
				title : '选择未签约学员导入模版',
				btn : [ '下载', '取消' ],
				type : 1,
				// skin: 'layui-layer-rim', //加上边框
				// area: ['620px', 'auto'], //宽高
				area : "30%",
				content : head+notSignBody+foot,
				yes : function(index, layerno) {
					var $layerno=$(layerno);
                    var valArr = new Array();
                    $layerno.find("input[type='checkbox']").each(function (i) {
                        if ($(this).is(':checked')) {
                            valArr.push($(this).val());
                        }
                    });
                    if (valArr.length == 0) {
                        layer.msg("请至少选中一个！", {icon: 2});
                        return;
                    }
                    // alert(valArr.join(","));
                    window.location.href="/download_template?ids="+valArr.join(",");
                    layer.close(index);

				},
				btn2 : function(index, layerno) {

				}
			});
    	});
    	
    }
    var handleSignTemplate = function () {        
    	$("#btn_sign").click(function(e){
    		e.preventDefault();
    		layer.open({
    			title : '选择签约会员导入模版',
    			btn : [ '是', '否' ],
    			type : 1,
    			// skin: 'layui-layer-rim', //加上边框
    			// area: ['620px', 'auto'], //宽高
    			area : "30%",
    			content : head+notSignBody+signBody+foot,
    			yes : function(index, layerno) {
    				var $layerno=$(layerno);
    				var areaName=$layerno.find("#childAreaName").val();
    				if (!areaName) {
    					layer.msg("亲，地区不能为空！", {
    						icon : 2
    					});
    					return;
    				}
    				
    				var post_data = {};
    				post_data.areaName=areaName;
    				post_data.areaParentId=roleId;
    				submitForm(JSON.stringify(post_data), "/studentareaadd");
    			},
    			btn2 : function(index, layerno) {
    				layer.msg("取消了", {
    					icon : 2
    				});
    			}
    		});
    	});
    	
    }

    var event=function () {
    	//1.切换批次类型事件
		$("input[name='batchType']").click(function () {
			// layer.alert($(this).val());
			let value=$(this).val();
			if (value==1){
				$("#txtBatchName").css("display","");
				$("#selectBatchName").css("display","none");

			}else{
                $("#txtBatchName").css("display","none");
                $("#selectBatchName").css("display","");
			}
        });
        // 3.批量导入
        $("#batch_import_stu").change(function() {

            var form_data = $("#batch_form").serializeArray();
            var post_data = {};
            $.map(form_data, function (n, i) {

                var key = n['name'];
                var value = n['value'];
                if (key && post_data.hasOwnProperty(key)) {
                    let originValue = post_data[key];
                    let newValue = originValue + "," + value;
                    post_data[key] = newValue;
                } else {
                    post_data[key] = value;
                }

            });
            //这里需要处理批次名称和批次ID
            // layer.alert($("input[name='batchType']").val());
			if ($("input[name='batchType']:checked").val()==1){
				//代表是新批次
				let batchName=$("input[name='batchName']").val();
				if (!batchName){
					layer.msg("请填写批次名称！",{icon:2});
					return;
				}
                post_data.batchName=batchName;
                post_data.id=0;

			}else{
				//追加历史批次
				let $select=$("select[name='batchName']");
                let bid=$select.val();

                if (!bid){
                    layer.msg("请选择批次名称！",{icon:2});
                    return;
                }
                post_data.batchName=bid;
                post_data.id=bid;
			}

             // layer.alert(JSON.stringify(post_data));

             // layer.msg("上传文件！");
            $.ajaxFileUpload({
                url : '/import_student_info',
                secureuri : false,
                fileElementId : "batch_import_stu",// file标签的id
                dataType : 'json',// 返回数据的类型
				data:post_data,//一同上传的数据
            	beforeSend : beginWait("数据导入中，请稍稍后。。。"),
				type:"POST",
                success : function(data, status) {
                    layer.msg(data.retMsg, {
                        icon : 1
                    });
                    setTimeout("window.location.reload();", 800);
                },
                error : function(data, status, e) {
                    layer.alert(e);
                }
            });
        });

        function beginWait(msg) {
            // 加载层-风格4
            layer.msg(msg, {
                icon : 16,
                shade : 0.01
            });
        }
    }
    return {
        init: function () {
        	 
        	handleNotSignTemplate();
        	handleSignTemplate();
        	event();
        }

    };
    
    

}();